#pragma once
#include"TcpServer.hpp"
#include"Protocol.hpp"
#include"ThreadPool.hpp"
#define PORT 8081
#define NUM 50
class HttpServer
{
private:
    TcpServer* tcpserver;
    int port;
    int listensock;
    int num;
public:
    HttpServer(int _port=PORT,int Num=NUM)
    :port(_port),num(Num),tcpserver(new TcpServer(_port)){}
    void Inital()
    {
        signal(SIGPIPE,SIG_IGN); //对信号SIGPIPE进行忽略
        tcpserver->initial();
        listensock=tcpserver->Sock();
    }
    void Loop()
    {
        while(1)
        {
            int sock=accept(listensock,nullptr,nullptr);
            if(sock>=0)
            {
                LOG(INFO,"new task is coming");
                Task task(sock);
                ThreadPool::getinstance(num)->PushTask(task);
                LOG(INFO,"new task is finished");
            }
        }
    }
};